﻿
using System;
using System.Data;
using System.Text;
using Yd.CommCls;

namespace Yd.Util
{
    /// <summary>
    /// 前台普通页面都要继承此类基类
    /// </summary>
    public class PBasePage : Base
    {
        /// <summary>
        /// 页面初始化
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            //if (CommCls.CommUtils.GetUserId() == "0")
            {
                //string login_page="/Login.aspx";
                //string pay_result = "/epay/PayResult.aspx";
                //string pay_notify = "/epay/PayNotify.aspx";
                //string upload_page = "/user/uploadPhoto.aspx";
                //string script_name=Request.ServerVariables["Script_Name"];
                //if (script_name != login_page && script_name!=pay_result && script_name!=pay_notify && script_name!=upload_page)
                //{
                //    Response.Redirect(login_page);
                //}
                    //return;
            }
            base.OnInit(e);
        }

        /*function Fround1(fmoneyf) {
        var _bj = Math.floor(fmoneyf);
        var _str = (_bj / 10).toFixed(1);
        var zhnum = _str.toString().substr(_str.toString().indexOf(".") + 1);
        if (parseInt(zhnum) <= 4) {
            _bj = Math.floor(_str) * 10;
        }
        if (parseInt(zhnum) > 5) {
            _bj = (Math.floor(_str) + 1) * 10;
        }
        if (parseInt(zhnum) == 5) {
            _bj = (parseFloat(_str)) * 10;
        }
        return _bj;
    }*/

        public decimal clmoney(decimal m)
        {
            decimal d = Math.Floor(m);
            string str = (d / 10).ToString("0.0");
            string s = str.Substring(str.IndexOf(".") + 1);
            if (s.StrToInt() > 5)
            {
                return ((Math.Floor(str.StrTodecimal())+1) * 10);
            }
            if (s.StrToInt() <=4)
            {
                return (Math.Floor(str.StrTodecimal()) * 10);
            }
            if (s.StrToInt() == 5)
            {
                return (str.StrTodecimal() * 10);
            }
            return m;
        }

        public string gets()
        {
            DataSet ds = commdal.QueryObjectAllSql("select top 8 * from View_tz_order where orderstate=1 order by Id desc");
            StringBuilder sb = new StringBuilder();
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {

                sb.Append("<li>");
                int n = 0;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    sb.Append("<div class=\"ssbbwz\"><h4>" + subs(dr["username"].ToString().Trim(),2) + "</h4>" + g1(dr["sfks"].ToString()) + " <span>" + jg(dr["pzje"].ToString(), dr["zhjine"].ToString()) + "</span> ，" + g1(dr["sfks"].ToString()) + "<span> " + dr["zhjine"].ToString() + "元</span><div class=\"ssbbimg\">");
                    sb.Append("<img src=\"images/ssbbright.jpg\" alt=\"\" align=\"absmiddle\"></div></div>");
                    n = n + 1;
                    if (n >= 4)
                    {
                        n = 0;
                        sb.Append("</li><li>");
                    }
                }
                if (n != 4)
                {
                    sb.Append("</li>");
                }

            }
            return sb.ToString().Trim().Replace("<li></li>","");
        }

        public string jg(string pzje, string jine)
        {
            decimal d = (jine.StrTodecimal() / pzje.StrTodecimal()) * 100;
            return Math.Round(d).ToString() + "%";
        }

        public string hs(object p)
        {
            if (p == null)
            {
                return "";
            }
            if (string.IsNullOrWhiteSpace(p.ToString().Trim()))
            {
                return "";
            }
            return "来自 " + p.ToString().Trim();
        }

        public string g(string fstate)
        {
            if (fstate.Trim() == "2")
            {
                return "亏损";
            }
            return "盈利";
        }

        public string g1(string fstate)
        {
            if (fstate.Trim() == "2")
            {
                return "亏损";
            }
            return "收获";
        }
    }
}
